/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.leo.jg;

import it.polimi.leo.mw.IMiddleWare.IMiddlewareMessageKind;
import it.polimi.leo.mw.IMiddleWareGroup;
import it.polimi.leo.mw.IMiddlewareMessage;
import org.jgroups.Message;

/**
 *
 * @author Lev
 */
public class JGMessage implements IMiddlewareMessage {

    IMiddleWareGroup group;
    IMiddlewareMessageKind kind;
    Object payload;

    JGMessage(IMiddleWareGroup group, IMiddlewareMessageKind kind,
            Object payload) {
        this.group = group;
        this.kind = kind;
        this.payload = payload;
    }

    JGMessage(IMiddlewareMessage msg) {
        this(msg.getGroup(), msg.getKind(), msg.getPayLoad());
    }

    JGMessage(Message mex) {
        this( (IMiddlewareMessage)mex.getObject() );
    }

    public JGMessage(Object data) {
        this( null, IMiddlewareMessageKind.DATA, data );
    }

    public Message get(){
        //TODO:
        Message res = new Message();
        res.setObject(this);
        return res;
    }

    public void setGroup(IMiddleWareGroup group) {
        this.group = group;
    }

    public void setKind(IMiddlewareMessageKind kind) {
        this.kind = kind;
    }

    public void setPayload(Object payload) {
        this.payload = payload;
    }

    public IMiddlewareMessageKind getKind() {
        return kind;
    }

    public IMiddleWareGroup getGroup() {
        return group;
    }

    public Object getPayLoad() {
        return payload;
    }
}
